﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>新增部位尺码值</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">所属部位</label>
            <div class="layui-input-inline">
                <select name="sel_bw" id="sel_bw" lay-filter="LAY-user-adminrole-type"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">对应尺码</label>
            <div class="layui-input-inline">
                <select name="sel_cm" id="sel_cm" lay-filter="LAY-user-adminrole-type"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部位值</label>
            <div class="layui-input-inline">
                <input type="text" name="bwvalue" id="bwvalue" placeholder="部位值" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否可用</label>
            <div class="layui-input-block">
                <input type="checkbox" id="isactive" checked="" name="open" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="可用|禁用">
            </div>
        </div>
        <div style="padding-bottom: 10px;text-align:center">
            <button class="layui-btn layuiadmin-btn-useradmin" data-type="add" id="LAY-user-front-submit">确认</button>
        </div>
    </div>

  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script src="../../../layuiadmin/js/jquery.min2.1.4.js"></script>
  <script src="../../../layuiadmin/js/jshelp.js"></script>
  <script>
      layui.config({
          base: '../../../layuiadmin/' //静态资源所在路径
      }).extend({
          index: 'lib/index' //主入口模块
      }).use(['index', 'form', 'upload'], function () {
          var $ = layui.$
              , form = layui.form
              , upload = layui.upload;

          //加载部位选项
          $.ajax({
              type: "post",
              url: "ashx/list.ashx?type=getselect_bw",
              dataType: "json",
              success: function (data) {
                  var html = '';
                  if (data.data.length == 0) {
                      html += "<option value=''>无数据</option>";
                      $("#sel_bw").empty().append(html);
                  } else {
                      html += "<option value=''>请选择数据</option>";
                      for (var i = 0; i < data.data.length; i++) {
                          html += "<option value='" + data.data[i].id + "'>" + data.data[i].bwothername + "</option>"
                      }
                      $("#sel_bw").empty().append(html);
                  }
                  form.render();
              },
              error: function (data) {
                  layer.error(data);
              }
          });
          //加载尺码选项
          $.ajax({
              type: "post",
              url: "ashx/list.ashx?type=getselect_cm",
              dataType: "json",
              success: function (data) {
                  var html = '';
                  if (data.data.length == 0) {
                      html += "<option value=''>无数据</option>";
                      $("#sel_cm").empty().append(html);
                  } else {
                      html += "<option value=''>请选择数据</option>";
                      for (var i = 0; i < data.data.length; i++) {
                          html += "<option value='" + data.data[i].id + "'>" + data.data[i].cmwm + "</option>"
                      }
                      $("#sel_cm").empty().append(html);
                  }
                  form.render();
              },
              error: function (data) {
                  layer.error(data);
              }
          });

          $("#LAY-user-front-submit").on('click', function () {
              var sel_bw = $("select[name='sel_bw']").val();
              var sel_cm = $("select[name='sel_cm']").val();
              var bwvalue = $("#bwvalue").val();
              var isactive = $("#isactive").prop("checked");
              var arr = new Array();
              if (sel_bw == "" || sel_bw == null || sel_bw == undefined) {
                  layer.msg('请选择所属部位', { icon: 5 });
                  return;
              }
              if (sel_cm == "" || sel_cm == null || sel_cm == undefined) {
                  layer.msg('请选择所属尺码', { icon: 5 });
                  return;
              }
              if (bwvalue == "" || bwvalue == null || bwvalue == undefined) {
                  layer.msg('请填写部位值', { icon: 5 });
                  return;
              }
              
              if (bwvalue != "") {
                  var add = {
                      "sel_bw": sel_bw,
                      "sel_cm": sel_cm,
                      "bwvalue": bwvalue,
                      "isactive": isactive
                  };
                  arr.push(add);
                  $.ajax({
                      url: 'ashx/list.ashx?type=add',
                      type: "post",
                      contentType: "application/json",
                      dataType: "json",
                      data: JSON.stringify({ 'LoadData_type': arr }),
                      success: function (res) {
                          var index = parent.layer.getFrameIndex(window.name);
                          if (res.flag=="True") {
                              layer.msg(res.remsg, {
                                  time: 2000,
                                  end: function () {
                                      parent.layer.close(index);
                                      window.parent.location.reload();
                                  }
                              })
                          }
                          else {
                              layer.alert(res.remsg);
                          }
                      }
                  })
              }
          });
     
  })
  </script>
</body>
</html>